package com.dubito.retrofit

import android.preference.Preference
import android.util.Log
import okhttp3.Interceptor
import okhttp3.Response

/**
 *author: liliang
 *date: 2020/9/7 9:05 PM
 *
 */
class HttpInterceptor: Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        // 这里设置
        val addHeader = request.newBuilder().addHeader("token", "121")
        val response = chain.proceed(request)
        response.header("x-access-token")?.let {
            Log.d("x-access-token:", it)
            // 这里保存
        }
        val body = response.peekBody(1024)
        return chain.proceed(addHeader.build())
    }
}